<%! func Search(w io.Writer,r *http.Request,q string,filter string,from int,size int,config *common.UIConfig, response *index.SearchResponse) error %>
<%% import "net/http" %%>
<%% import "github.com/infinitbyte/gopa/ui/search/common" %%>
<%% import "github.com/infinitbyte/framework/core/index" %%>
<%% import "github.com/infinitbyte/framework/core/util" %%>
<%% import "fmt" %%>
<%% import "strings" %%>

<!DOCTYPE html>
<!--[if lt IE 7 ]> <html class="no-js ie6" lang="en-US"> <![endif]-->
<!--[if IE 7 ]>    <html class="no-js ie7" lang="en-US"> <![endif]-->
<!--[if IE 8 ]>    <html class="no-js ie8" lang="en-US"> <![endif]-->
<!--[if (gte IE 9)|!(IE)]><!--> <html lang="en-US"> <!--<![endif]-->

<head>
    <title><%= q %> | <%= config.SiteName %></title>
    <% CommonHeader(w,config) %>
    <link rel="stylesheet" href="/static/assets/css/search/search.css" rel="stylesheet" type="text/css"/>
</head>

<body link=#0000cc>

<div id=out>
    <div id=in>
        <div id=wrapper >

            <div id=head>
                <div class="global_left">

                    <div class=nv>
                        <a class=logo  href="/">
                            <img border=0  style="margin-bottom:-55px;height:45px"   src="<%= config.SiteLogo %>">
                        </a>

                    </div>


                    <div id="toolbar_wrapper">
                        <div id="search-context">
                            <a href="#" class="active" context="default" suggest_url="/suggest/"></a>
                        </div>
                        <svg xmlns="http://www.w3.org/2000/svg" style="display:none">
                            <symbol xmlns="http://www.w3.org/2000/svg" id="sbx-icon-search-6" viewBox="0 0 40 40">
                                <path d="M28.295 32.517c-2.93 2.086-6.51 3.312-10.38 3.312C8.02 35.83 0 27.81 0 17.914 0 8.02 8.02 0 17.915 0 27.81 0 35.83 8.02 35.83 17.915c0 3.87-1.227 7.45-3.313 10.38l6.61 6.61c1.166 1.165 1.163 3.057 0 4.22-1.167 1.167-3.057 1.167-4.226-.002l-6.605-6.606zm-10.38.326c8.245 0 14.928-6.683 14.928-14.928 0-8.245-6.683-14.93-14.928-14.93-8.245 0-14.93 6.685-14.93 14.93 0 8.245 6.685 14.928 14.93 14.928zm0-26.573c-6.43 0-11.645 5.214-11.645 11.645 0 .494.4.895.896.895.495 0 .896-.4.896-.895 0-5.442 4.41-9.853 9.853-9.853.494 0 .895-.4.895-.896 0-.495-.4-.896-.895-.896z"
                                      fill-rule="evenodd" />
                            </symbol>
                            <symbol xmlns="http://www.w3.org/2000/svg" id="sbx-icon-clear-3" viewBox="0 0 20 20">
                                <path d="M8.114 10L.944 2.83 0 1.885 1.886 0l.943.943L10 8.113l7.17-7.17.944-.943L20 1.886l-.943.943-7.17 7.17 7.17 7.17.943.944L18.114 20l-.943-.943-7.17-7.17-7.17 7.17-.944.943L0 18.114l.943-.943L8.113 10z" fill-rule="evenodd" />
                            </symbol>
                        </svg>
                        <form name="f" id="f" novalidate="novalidate" class="searchbox sbx-custom" action="/" onSubmit="submitSearch()">
                            <div role="search" class="sbx-custom__wrapper">
                                <input name="q"
                                       placeholder="Please type to search ..."
                                       value="<%= q %>"   autocomplete="off" required="required"
                                       id="query"  maxLength=100 role="textbox"
                                       accesskey="s" type="text" x-webkit-speech="" speech="" spellcheck="false"
                                       class="sbx-custom__input" >
                                <button type="submit" title="Submit your search query." class="sbx-custom__submit">
                                    <svg role="img" aria-label="Search">
                                        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#sbx-icon-search-6"></use>
                                    </svg>
                                </button>
                                <button type="reset" title="Clear the search query." class="sbx-custom__reset">
                                    <svg role="img" aria-label="Reset">
                                        <use xmlns:xlink="http://www.w3.org/1999/xlink" xlink:href="#sbx-icon-clear-3"></use>
                                    </svg>
                                </button>
                            </div>
                        </form>
                    </div>
                    <div id="toolbar_baseline" class="toolbar_baseline"></div>
                    <div style="padding-top:5px;padding-bottom: 5px;">
                        <SPAN style="float: left;" class=nums>About <%= response.Hits.Total %> results (<span><%= response.Took %>ms</span>)</SPAN>
                    </div>
                </div>
            </div>
            <div style=" clear: both;height: 10px;"></div>
            <div class="global_left">

                <div id=container >

                    <div style=" width: 600px;clear: both;">


                        <div style="height:0px; float:left; padding-left:585px;">
                            <div style="font-size: 12px;width:300px;WORD-BREAK: break-all; WORD-WRAP: break-word; overflow:hidden">
                                <% if len(response.Aggregations)>0 { %>

                                <ul class="middle_column_ul">
                                <%

                                for k,v:=range response.Aggregations{
                                    if(len(v.Buckets)>0){
                                %>
                                    <li style="background: #eeeeee; " >
                                        <div style="padding:5px 10px; font-size: 14px;"><%= common.GetBucketLabel(k) %></div>

                                        <div style="padding:0px 0px; background:#f8f8f8;text-decoration: none;">
                                            <ul >
                                <%
                                for _,bkt:=range v.Buckets{
                                key:=bkt.Key
                                c:=bkt.DocCount
                                %>
                                <li><a href=<%==fmt.Sprintf("?q=%s&filter=%s|%v&from=0",q,common.GetBucketKey(k),util.UrlEncode(key)) %> ><%= key %><count>(<%= c %>)</count></a></li>

                                <% } %>
                                            </ul>
                                        </div>
                                    </li>
                                <%
                                }}
                                %>

                                </ul>
                                <%
                                }
                                %>
                            </div>
                        </div>

                        <%
                        hasResult:= len(response.Hits.Hits)>0

                        if hasResult { %>
                        <div class="item-view">
                        <%
                        for seq,hit:=range response.Hits.Hits{
                            url:=common.SafeGetField(hit.Source["snapshot"].(map[string]interface{})["url"],"N/A")
                            snapshotId:=common.SafeGetField(hit.Source["snapshot"].(map[string]interface{})["id"],"")
                            screenshot:=common.SafeGetField(hit.Source["task"].(map[string]interface{})["last_screenshot_id"],"")
                            title:=common.SmartGetField(hit.Highlight["snapshot.title"],hit.Source["snapshot"].(map[string]interface{})["title"],"N/A")
                            summary:=util.SubStringWithSuffix(common.SmartGetField(hit.Highlight["snapshot.text"],hit.Source["snapshot"].(map[string]interface{})["text"],"N/A"),500,"...")
                        %>
                            <TABLE id=result_<%= seq %> class=result cellSpacing=0 cellPadding=0> <TBODY><TR>
                                <TD class=f>
                                    <H3 class=t><A  title='<%= hit.Source["snapshot"].(map[string]interface{})["title"] %>' href="<%= url %>"  target=_blank>
                                        <%== util.SubStringWithSuffix(title,500,"...") %></A> </H3>
                                    <FONT size=-1><% if(screenshot!=""){ %>
                                        <img class="screenshot" src="/screenshot/<%== screenshot %>" class="uk-icon-hover uk-icon-history" />
                                        <% } %>
                                        <%== summary %> <BR>
                                        <div  class=g><a target=_blank href="<%= url %>"><%=util.SubStringWithSuffix(url,80,"...") %></a>
                                            <% if(snapshotId!=""){ %>
                                            <a target="_blank" href="/snapshot/<%== snapshotId %>" class="uk-icon-hover uk-icon-history"></a>
                                            <% } %>
                                        </div>
                                    </FONT>
                                </TD>
                            </TR></TBODY></TABLE>
                        <%
                        }%>
                        </div>
                        <%


                        paras:=map[string]interface{}{}
                        paras["q"]=q

                        if(filter!=""&&strings.Contains(filter,"|")){
                            paras["filter"]=filter
                        }
                        %>

                        <%}else{%>
                        <div class="uk-alert uk-alert-warning"> Nothing found.</div>
                        <%}%>



                        <%
                        if hasResult && response.Hits.Total>10{
                        %>
                        <div class="loadmore">
                            <div class="pnnext" data-total="<%= response.Hits.Total %>" data-from="<%= from %>" data-size="<%= size %>" data-load-text="Loading ...">
                                <span class="load-icon"></span><span class="load-text">Load More</span>
                            </div>
                            <p class="load-tips"></p>
                        </div>
                        <%
                        }%>

                        <div class="c-back">
                            <div class="back-top">
                                <svg class="icon" viewBox="0 0 1024 1024" version="1.1" xmlns="http://www.w3.org/2000/svg" p-id="519">
                                    <path d="M873.6 419.2l-355.2-361.6c-9.6-9.6-22.4-9.6-32 0l-355.2 368c-9.6 9.6-9.6 22.4 0 32 9.6 9.6 22.4 9.6 32 0l316.8-329.6 0 828.8c0 12.8 9.6 22.4 22.4 22.4s22.4-9.6 22.4-22.4l0-822.4 310.4 316.8c9.6 9.6 22.4 9.6 32 0C883.2 441.6 883.2 425.6 873.6 419.2z" p-id="520">
                                    </path>
                                </svg>
                            </div>
                        </div>

                    </div>

                    <div class="copyright">
                        <br/>
                        <% common.Copyright(w,config) %>
                    </div>

                </div>

            </div>

        </div>
    </div>
</div>

<% CommonFooter(w) %>

<script src="/static/assets/uikit-2.27.1/js/components/pagination.min.js"></script>

</body>
</html>
